home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / QFLOAT / MULR.ASM < prev    next >
Assembly Source File  |  1996-02-24  |  2KB  |  197 lines

  1. ;    Static Name Aliases
  2. ;
  3.     TITLE   mulm
  4.  
  5. include qhead.asm
  6.  
  7. _DATA    SEGMENT
  8. temp    DW    NQ+2 DUP (?)
  9. _DATA    ENDS
  10.  
  11. _TEXT      SEGMENT
  12.  
  13. ; Multiply mantissa of x by mantissa of y, result to y
  14. ; subm( x, y )
  15.     PUBLIC    _mulm
  16. _mulm    PROC NEAR
  17.     push    bp
  18.     mov    bp,sp
  19.     push    si
  20.     push    di
  21.     push    ax
  22.     push    bx
  23.     push    cx
  24.     push    dx
  25.     push    es
  26.  
  27.     push    ds
  28.     pop    es
  29.  
  30. ; temp area for the product
  31.     lea    bx,temp
  32. ; clear the temp area
  33.     xor    ax,ax
  34.     mov    di,bx
  35.     mov    cx,NQ+2
  36.     rep    stosw
  37.  
  38.     mov    si,WORD PTR [bp+4]    ;source
  39.     mov    di,WORD PTR [bp+6]    ;dest
  40.  
  41.     xor    cx,cx    ; for adc 0
  42.  
  43. hh = OMG-1
  44.  
  45. rept OMG-1
  46.  
  47. g = 0
  48. h = hh
  49. rept (hh+1)/2
  50. if g LE OMG-2
  51. if h LE OMG-2
  52.     zmul    g,h
  53.     zmul    h,g
  54. endif
  55. endif
  56. g = g+1
  57. h = h-1
  58. endm
  59.  
  60. if g EQ h
  61.     zmul    g,g
  62. endif
  63.  
  64. hh = hh-1
  65.  
  66. endm
  67.  
  68.     zmul    0,0
  69.  
  70. mulnorm:
  71.  
  72.     call    mdnorm
  73.  
  74.     mov    si,bx
  75.     add    si,4
  76.     add    di,4
  77.     mov    cx,OMG
  78.     rep    movsw
  79.  
  80.  
  81.     pop    es
  82.     pop    dx
  83.     pop    cx
  84.     pop    bx
  85.     pop    ax
  86.     pop    di
  87.     pop    si
  88.     pop    bp
  89.     ret    
  90. _mulm    ENDP
  91.  
  92.  
  93.  
  94. ; Source has at most 16 significant bits
  95.  
  96.     PUBLIC    _mulin
  97. _mulin    PROC NEAR
  98.     push    bp
  99.     mov    bp,sp
  100.     push    si
  101.     push    di
  102.     push    ax
  103.     push    bx
  104.     push    cx
  105.     push    dx
  106.     push    es
  107.  
  108.     push    ds
  109.     pop    es
  110.  
  111. ; temp area
  112.     lea    bx,temp
  113. ; clear the temp area
  114.     xor    ax,ax
  115.     mov    di,bx
  116.     mov    cx,NQ+2
  117.     rep    stosw
  118.  
  119.     mov    si,WORD PTR [bp+4]    ;source
  120.     mov    di,WORD PTR [bp+6]    ;dest
  121.  
  122.     xor    cx,cx    ; for adc 0
  123.  
  124.  
  125. h = OMG-2
  126.  
  127. rept OMG-1
  128.     zmul    h,0
  129. h = h-1
  130. endm
  131.  
  132.     jmp    mulnorm
  133.  
  134. _mulin    ENDP
  135.  
  136.  
  137.  
  138. ; normalize and round off
  139. ; enter with source = bx, dest = di
  140.  
  141.     PUBLIC mdnorm
  142. mdnorm    PROC NEAR
  143.  
  144.     mov    cx,3
  145. $normlp:
  146.     test    word ptr [bx]+6,08000H
  147.     jnz    $round
  148.  
  149. ; shift up 1 bit and decrement exponent
  150. g = NQ+NQ
  151.     clc
  152. rept OMG
  153.     rcl    word ptr [bx]+g,1
  154. g = g-2
  155. endm
  156.     sub    word ptr [di]+2,1
  157.     loop    $normlp
  158.  
  159. $round:
  160.  
  161.  
  162. ; round off
  163. g = NQ+NQ
  164.     test    word ptr [bx]+g,08000H
  165.     jnz    $doround
  166.     jmp    $done
  167.  
  168. $doround:
  169.     xor    cx,cx
  170. g = NQ+NQ-2
  171.     add    word ptr [bx]+g,1
  172. rept OMG-1
  173. g = g-2
  174.     adc    word ptr [bx]+g,cx
  175. endm
  176.  
  177. ; check for overflow on rounding up
  178.     test    word ptr [bx]+4,0FFFFH
  179.     jz    $done
  180.  
  181. ; shift down 1 bit and increment exponent
  182. g = 4
  183.     clc
  184. rept OMG
  185.     rcr    word ptr [bx]+g,1
  186. g = g+2
  187. endm
  188.     add    word ptr [di]+2,1
  189.  
  190.  
  191. $done:
  192.     ret
  193. mdnorm    ENDP
  194.  
  195. _TEXT    ENDS
  196. END
  197.